@extends('layouts.default') @section('main')
<link rel="stylesheet" href="/css/uniform.css" />
<link rel="stylesheet" href="/css/select2.css" />
<div id="content">
  <div id="content-header">
    <div id="breadcrumb"> <a href="{{url('role')}}" title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a> <a href="#" class="current">用户管理</a> </div>
  </div>
  <div class="container-fluid">
    <div class="row-fluid">
      <div class="span12">
      	@if(in_array('add',$actions))
      	<a href="{{url('roleuser/create')}}"><button class="btn">新增</button></a>
      	@endif
        <div class="widget-box">
          <div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>
            <h5>用户管理</h5>
          </div>
          <div class="widget-content nopadding">
            <table class="table table-bordered table-striped">
              <thead>
                <tr>
                  <th>账号</th>
                  <th>姓名</th>
                  <th>邮箱</th>
                  <th>注册时间</th>
                  <th>操作</th>
                </tr>
              </thead>
              <tbody>
              	@foreach($users as $key => $user)
                <tr class="gradeX">
                  <td>{{$user->username}}</td>
                  <td>{{$user->nickname}}</td>
                  <td>{{$user->email}}</td>
                  <td class="center">{{date('Y-m-d',$user->created_at)}}</td>
                  <td class="center"> 
                  	  @if(in_array('role',$actions))
	                  <a data-original-title="分配角色" class="tip" href="{{action('RoleController@getAssign',['uid'=>$user->id])}}">角色</a>
	                  @endif
	                  @if(in_array('edit',$actions))
	                  <a data-original-title="编辑" class="tip" href="{{action('RoleUserController@getEdit',['uid'=>$user->id])}}"><i class="icon-pencil"></i></a> 
	                  @endif
	                  @if(in_array('delete',$actions))
	                  <a data-original-title="删除" data-toggle="modal" class="tip user_delete" user_id="{{$user->id}}" href="#myAlert"><i class="icon-remove"></i></a> 
	                  @endif 
                  </td>
                </tr>
                @endforeach
              </tbody>
            </table>
          </div>
        </div><?php echo $users->render();?>
      </div>
    </div>
  </div>
</div>
<div>
	<div id="myAlert" class="modal hide">
		<div class="modal-header">
			<button data-dismiss="modal" class="close" type="button">×</button>
			<h3>提示</h3>
		</div>
		<div class="modal-body">
			<p>确认删除这条数据吗？</p>
		</div>
		<div class="modal-footer">
			<a data-dismiss="modal" class="btn btn-primary" href="javascript:void(0);">确定</a>
			<a data-dismiss="modal" class="btn" href="javascript:void(0);">取消</a>
		</div>
	</div>
	<form action="{{url('roleuser/delete')}}" method="post" id="roleForm">
		<input type="hidden" name="uid" value="0">
	</form>
</div>
<script src="/js/jquery.min.js"></script> 
<script src="/js/matrix.tables.js"></script>
<script src="/js/common.js"></script> 
<script>
$(".user_delete").click(function(){
	var user_id = $(this).attr("user_id");
	$("input[name='uid']").val(user_id);
});
$(".btn-primary").click(function(){
	var user_id = $("input[name='uid']").val();
	if(user_id == 0){
		alert('参数异常');
		return;
	}
	ajaxRequest($('#roleForm').serializeArray(),$('#roleForm').attr('action'),function(data){
		if(data.status){
			window.location.href = data.forwardUrl;
		}else{
			alert(data.message);
		}
	});
});
</script>
@stop
